/**
 * Created by Eoly on 2017/1/3.
 */
function Color(r, g, b, a) {
    this.r = r;
    this.g = g;
    this.b = b;
    this.a = a;
}
Color.prototype = {
    constructor: Color,

    setRGBA:function (r, g, b, a) {
        this.r = r;
        this.g = g;
        this.b = b;
        this.a = a;
    },

    checkCompleted: function () {
        if (this.r == null || this.g == null || this.b == null) {
            console.warn("颜色属性不完整");
            return false;
        }
        if ((this.r < 0 && this.r > 255) || (this.g < 0 && this.g > 255) || (this.b < 0 && this.b > 255)) {
            console.warn("颜色属性值异常");
            return false;
        }
        return true;
    },

    checkAlpha: function () {
        if (this.a == null) {
            console.warn("Alpha值未设置");
            return false;
        }
        if (this.a < 0 || this.a > 1) {
            console.warn("Alpha值异常");
            return false;
        }
        return true;
    },

    getHexColor: function () {
        if (this.checkCompleted()) {
            var r = ("0" + this.r.toString(16)).slice(-2);
            var g = ("0" + this.g.toString(16)).slice(-2);
            var b = ("0" + this.b.toString(16)).slice(-2);
            return "#" + r + g + b;
        }
        return ""
    },

    getRGBA: function () {
        if (this.checkCompleted() && this.checkAlpha()) {
            return "rgba(" + this.r + "," + this.g + "," + this.b + "," + this.a + ")";
        }
        return ""
    },

    getRGB: function () {
        if (this.checkCompleted()) {
            return "rgba(" + this.r + "," + this.g + "," + this.b + ")";
        }
        return ""
    }
};